package com.example.mydemo2;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import java.util.List;

public class OrdersListAdapter extends RecyclerView.Adapter<OrdersListAdapter.MyViewHolder> {
    //创建一个list类型的apps
    private List<OrdersItem> ordersItems;
    public void setData(List<OrdersItem> ordersItems){
        this.ordersItems = ordersItems;

    }

    @NonNull
    @Override
    public MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_oder_list,parent,false);

        return new MyViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull MyViewHolder holder, int position) {
        OrdersItem ordersItem = ordersItems.get(position);
        holder.orderDate.setText(ordersItem.getOrderDate());
        holder.salePeople.setText(ordersItem.getSalePeople());
        holder.recyclePeople.setText(ordersItem.getRecyclePeople());
        holder.thingType.setText(ordersItem.getThingType());
        holder.totalCount.setId(ordersItem.getTotalCount());
        holder.price.setId(ordersItem.getPrice());
        holder.total.setId(ordersItem.getTotal());
    }

    @Override
    public int getItemCount() {

        return ordersItems == null ? 0:ordersItems.size();
    }
    static class MyViewHolder extends RecyclerView.ViewHolder {
            TextView orderDate;
            TextView salePeople;
            TextView recyclePeople;
            TextView thingType;
            TextView totalCount;
            TextView price;
            TextView total;

        public MyViewHolder(@NonNull View itemView) {
            super(itemView);
            orderDate = itemView.findViewById(R.id.tv_date);
            salePeople = itemView.findViewById(R.id.tv_sale_people);
            recyclePeople = itemView.findViewById(R.id.tv_recycle_name);
            thingType = itemView.findViewById(R.id.tv_type_thing);
            totalCount = itemView.findViewById(R.id.tv_count_number);
            price = itemView.findViewById(R.id.tv_price_number);
            total = itemView.findViewById(R.id.tv_total_number);



        }
    }
}
